var fs =require("fs");
var path=require("path");
var http=require("http");


http.createServer((req,res) => {
    var fileName=process.argv[2] 
    var filePath=path.join(__dirname,"/"+fileName)
    var filePath1=path.join(__dirname,"/fileReader3.js");

    if(fs.existsSync(filePath)){
        var readable=fs.createReadStream(filePath);
        readable.on("data",function(chunk){
          console.log(chunk.toString("utf-8"));
        })
        readable.on("end",function(){
            console.log("readable ended");
        })
        readable.pipe(res);
    }else if(fileName==undefined){
      var readable=fs.createReadStream(filePath1);
        readable.on("data",function(chunk){
          console.log(chunk.toString("utf-8"));
        })
        readable.on("end",function(){
            console.log("readable ended");
        })
        readable.pipe(res);
    }
}).listen(8081);
console.log("server is listening 8081");